refactor(server): clean up cluster.rs + fix gossip borrow warning - #191
Merged
Conversation
cluster.rs:
- add ELECTION_STAGGER_MS, ELECTION_TIMEOUT_SECS, FAILOVER_GRACE_MS,
and REPLICATION_PORT_OFFSET constants to replace inline literals
- extract replication_port(data_port) helper used by both the
replication server and client; avoids repeating the three-step
checked_add arithmetic
- replace explicit drop(gossip)/drop(state) in save_config with
scoped blocks — idiomatic and signals clear intent
- unify raft_error_frame to build the message string first, then
wrap it in Frame::Error("ERR {msg}") — previously two arms used
.into() and one used format!()
- move PostAction enum definition outside the event loop; add a
comment explaining the deadlock-avoidance pattern
- replace 500/5/500 ms/s magic literals in start_election and
cluster_failover with the new constants
gossip.rs (follow-up to #190):
- restructure the SlotsChanged apply arm to use a bool flag so the
mutable borrow on `member` ends before the async emit call; this
removes the drop(member) reference warning emitted by rustc
kacy
added a commit
that referenced
this pull request
Feb 19, 2026
cluster.rs:
- add ELECTION_STAGGER_MS, ELECTION_TIMEOUT_SECS, FAILOVER_GRACE_MS,
and REPLICATION_PORT_OFFSET constants to replace inline literals
- extract replication_port(data_port) helper used by both the
replication server and client; avoids repeating the three-step
checked_add arithmetic
- replace explicit drop(gossip)/drop(state) in save_config with
scoped blocks — idiomatic and signals clear intent
- unify raft_error_frame to build the message string first, then
wrap it in Frame::Error("ERR {msg}") — previously two arms used
.into() and one used format!()
- move PostAction enum definition outside the event loop; add a
comment explaining the deadlock-avoidance pattern
- replace 500/5/500 ms/s magic literals in start_election and
cluster_failover with the new constants
gossip.rs (follow-up to #190):
- restructure the SlotsChanged apply arm to use a bool flag so the
mutable borrow on `member` ends before the async emit call; this
removes the drop(member) reference warning emitted by rustc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
summary
a focused cleanup of
cluster.rsnow that the phase 6 failover and replication code has settled. also includes a small follow-up fix togossip.rs(from #190) that rustc flagged.cluster.rs
ELECTION_STAGGER_MS(500),ELECTION_TIMEOUT_SECS(5),FAILOVER_GRACE_MS(500),REPLICATION_PORT_OFFSET(2)replication_port(data_port)helper centralizes thedata + offset + 2arithmetic that previously appeared inline instart_replication_serverandstart_replication_clientsave_configdrops the explicitdrop(gossip)/drop(state)calls in favour of scoped blocks — the lock guard lifetimes are now obvious from structure aloneraft_error_framebuilds the message string in amatch, then wraps it once withFrame::Error(format!("ERR {msg}"))— previously two arms used.into()and one usedformat!()inconsistentlyPostActionis defined once before thewhile letloop, not re-defined on each iteration; a comment explains the deadlock-avoidance pattern it implementsstart_electionTODO-style comment is replaced with a short note explaining why a fixed stagger delay is used today and what the correct implementation would requiregossip.rs
the
SlotsChangedarm now uses ashould_emit: boolflag so the mutable borrow onmemberends before the asyncself.emitcall. this removes thedrop(member)reference warning that rustc emitted after #190.what was tested
cargo build -p ember-server— clean, no warningscargo test -p ember-server -p ember-cluster -p emberkv-core -p ember-persistence -p ember-protocol— all pass